package com.chouren.goandroid.img;

import java.io.File;
import java.io.IOException;

import android.content.Context;

public class FileCache {
	private String cacheDir;
	
	public FileCache(Context context) {
		cacheDir = FileCacheManager.getCacheDir(context);
	}
	
	public File getCacheFile(String url) {
		File file = new File(cacheDir + "/" + url.hashCode());
		if(!file.exists()) {
			try {
				if(file.getParent() == null) new File(file.getParent()).mkdirs();
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return file;
	}
	
	public String getCacheFileAbsolutePath(String url) {
		return cacheDir + "/" + url.hashCode();
	}
	
	public String getCacheDir() {
		return cacheDir;
	}
	
	public void clear() {
		FileCacheManager.deleteDirectory(cacheDir);
	}
	
	public boolean createCacheFile(String url) {
		boolean result = false;
		File file = new File(cacheDir + "/" + url.hashCode());
		try {
			result = file.createNewFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
}
